package com.smartstate.admin.biz.entity.vo;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.smartstate.admin.biz.convert.GenderConverter;
import com.smartstate.admin.biz.entity.bo.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@HeadFontStyle(fontHeightInPoints = 15)
@NoArgsConstructor
public class UserExcelVo implements Serializable {

    @ExcelIgnore
    private static final long serialVersionUID = 1L;

    /**
     * 用户id
     */
    @ExcelIgnore
    private String id;

    /**
     * 用户名
     */
    @ExcelProperty("账号(必填)")
    @ColumnWidth(20)
    private String username;

    /**
     * 用户昵称
     */
    @ColumnWidth(20)
    @ExcelProperty("姓名(必填)")
    private String nickname;

    @ExcelProperty("角色名称(必填)")
    @ColumnWidth(20)
    @ApiModelProperty(value = "角色名称")
    private String roleName;

    /**
     * 年龄
     */
    @ColumnWidth(10)
    @ExcelProperty("年龄")
    private Integer age;

    /**
     * 性别 1:男 2:女
     */
    @ColumnWidth(20)
    @ExcelProperty(value = "性别(男:女)",converter = GenderConverter.class)
    private Integer sex;

    /**
     * 生日
     */
    @ExcelIgnore
    private LocalDateTime birthday;

    /**
     * 手机号
     */
    @ColumnWidth(20)
    @ExcelProperty("手机号")
    private String phone;

    /**
     * 邮箱
     */
    @ColumnWidth(20)
    @ExcelProperty("邮箱")
    private String email;

    /**
     * 省
     */
    @ExcelIgnore
    private String province;

    /**
     * 市
     */
    @ExcelIgnore
    private String city;

    /**
     * 区
     */
    @ExcelIgnore
    private String area;

    /**
     * 住址
     */
    @ExcelIgnore
    @ExcelProperty("住址")
    private String address;

    /**
     * 后台用户头像
     */
    @ExcelIgnore
    private String headImage;

    /**
     * 部门id 一个用户只有 一个部门
     */
    @ExcelIgnore
    private String deptId;

    /**
     * 企业id
     */
    @ExcelIgnore
    private String enterpriseId;

    /**
     * 0无效 1有效
     */
    @ExcelIgnore
    private Integer status;

    /**
     * 0无效 1有效
     */
    @ExcelIgnore
    private boolean blStatus;
    /**
     * 最后登录IP
     */
    @ExcelIgnore
    private String lastLoginIp;

    /**
     * 最后登陆时间
     */
    @ExcelIgnore
    @DateTimeFormat("yyyy-MM-dd")
    private LocalDateTime lastLoginTime;
    @ExcelIgnore
    @ApiModelProperty(value = "token")
    private String accessToken;

    @ExcelIgnore
    @ApiModelProperty(value = "部门名称")
    private String deptName;
    @ExcelIgnore
    @ApiModelProperty(value = "企业名称")
    private String compName;
    /**
     * 是否更新密码
     */
    @ExcelIgnore
    @ApiModelProperty("是否更新密码")
    private Boolean updatePassword;
    @ExcelIgnore
    @ApiModelProperty("角色信息")
    private RoleVo roleInfo;
    /**
     * bo转vo
     *
     * @param user
     * @return
     */
    public UserExcelVo buildVo(User user) {
        BeanUtils.copyProperties(user, this);
        return this;
    }

    /**
     * bo转vo
     * @param list
     * @return
     */
    public List<UserExcelVo> buildVoList(List<User> list) {
        List<UserExcelVo> voList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)) {
            return voList;
        }
        list.forEach(item -> {
            UserExcelVo vo = new UserExcelVo();
            BeanUtils.copyProperties(item, vo);
            voList.add(vo);
        });
        return voList;
    }
}
